package com.songqi.common.core.domain.page;

import com.songqi.common.core.utils.StringUtils;
import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * 分页请求数据
 *
 * @author songqi(13776346982)(13776346982)
 */
public class PageDomain implements Serializable
{
    /** 当前记录起始索引 */
    @ApiModelProperty(value = "页码。1：表示第一页", required = true)
    @NotNull(message = "页码参数必须填写")
    private Integer pageNum;

    /** 每页显示记录数 */
    @ApiModelProperty(value = "每页显示记录数", required = true)
    @NotNull(message = "每页显示记录数参数必须填写")
    private Integer pageSize;


    /** 排序列 */
    @ApiModelProperty("排序列。已过期")
    @Deprecated
    private String orderByColumn;

    /** 排序的方向desc或者asc */
    @ApiModelProperty(value = "排序的方向desc或者asc。已过期", allowableValues = "desc,asc")
    @Deprecated
    private String isAsc = "asc";

    @ApiModelProperty("排序")
    private String[] orderList;

    @ApiModelProperty("排序字段")
    private String[] sortFieldList;



    public String getOrderBy()
    {
        if (StringUtils.isEmpty(orderByColumn))
        {
            return "";
        }
        return StringUtils.toUnderScoreCase(orderByColumn) + " " + isAsc;
    }

    public Integer getPageNum()
    {
        return pageNum;
    }

    public void setPageNum(Integer pageNum)
    {
        this.pageNum = pageNum;
    }

    public Integer getPageSize()
    {
        return pageSize;
    }

    public void setPageSize(Integer pageSize)
    {
        this.pageSize = pageSize;
    }

    public String getOrderByColumn()
    {
        return orderByColumn;
    }

    public void setOrderByColumn(String orderByColumn)
    {
        this.orderByColumn = orderByColumn;
    }

    public String getIsAsc()
    {
        return isAsc;
    }

    public void setIsAsc(String isAsc)
    {
        if (StringUtils.isNotEmpty(isAsc))
        {
            // 兼容前端排序类型
            if ("ascending".equals(isAsc))
            {
                isAsc = "asc";
            }
            else if ("descending".equals(isAsc))
            {
                isAsc = "desc";
            }
            this.isAsc = isAsc;
        }
    }

    public String[] getOrderList() {
        return orderList;
    }

    public void setOrderList(String... orderList) {
        this.orderList = orderList;
    }

    public String[] getSortFieldList() {
        return sortFieldList;
    }

    public void setSortFieldList(String... sortFieldList) {
        this.sortFieldList = sortFieldList;
    }
}
